#整个代码交给ai说自己在做AIAgent这是tools.py，你需要什么功能加进去
import os
import subprocess
import shutil
from typing import List, Dict, Optional, Any

class FileTools:
    """文件操作工具类"""
    
    @staticmethod
    def create_text_file(file_path: str, content: str) -> Dict[str, Any]:
        """
        创建文本文件并写入内容
        
        Args:
            file_path: 文件路径
            content: 要写入的内容
            
        Returns:
            包含操作结果的字典
        """
        try:
            os.makedirs(os.path.dirname(file_path), exist_ok=True)
            with open(file_path, 'w', encoding='utf-8') as f:
                f.write(content)
            return {"success": True, "message": f"文件 '{file_path}' 创建成功"}
        except Exception as e:
            return {"success": False, "message": f"创建文件失败: {str(e)}"}
    
    @staticmethod
    def create_python_file(file_path: str, code: str) -> Dict[str, Any]:
        """
        创建Python文件并写入代码
        
        Args:
            file_path: 文件路径
            code: Python代码内容
            
        Returns:
            包含操作结果的字典
        """
        return FileTools.create_text_file(file_path, code)
    
    @staticmethod
    def get_directory_structure(directory: str, show_files: bool = True) -> Dict[str, Any]:
        """
        获取目录结构
        
        Args:
            directory: 目录路径
            show_files: 是否显示文件，默认为True
            
        Returns:
            包含目录结构的字典
        """
        try:
            if not os.path.exists(directory):
                return {"success": False, "message": f"目录 '{directory}' 不存在"}
            
            structure = {}
            for item in os.listdir(directory):
                item_path = os.path.join(directory, item)
                if os.path.isdir(item_path):
                    structure[item] = FileTools.get_directory_structure(item_path, show_files)
                elif show_files:
                    structure[item] = None  # 文件用None表示
            
            return {"success": True, "structure": structure}
        except Exception as e:
            return {"success": False, "message": f"获取目录结构失败: {str(e)}"}
    
    @staticmethod
    def rename_file(old_path: str, new_name: str) -> Dict[str, Any]:
        """
        重命名文件
        
        Args:
            old_path: 旧文件路径
            new_name: 新文件名
            
        Returns:
            包含操作结果的字典
        """
        try:
            if not os.path.exists(old_path):
                return {"success": False, "message": f"文件 '{old_path}' 不存在"}
            
            directory = os.path.dirname(old_path)
            new_path = os.path.join(directory, new_name)
            
            os.rename(old_path, new_path)
            return {"success": True, "message": f"文件已重命名为 '{new_path}'"}
        except Exception as e:
            return {"success": False, "message": f"重命名文件失败: {str(e)}"}

class CommandTools:
    """命令行工具类"""
    
    @staticmethod
    def execute_windows_command(command: str, wait_for_completion: bool = True) -> Dict[str, Any]:
        """
        执行Windows命令行命令
        
        Args:
            command: 要执行的命令
            wait_for_completion: 是否等待命令执行完成，默认为True
            
        Returns:
            包含命令执行结果的字典
        """
        try:
            process = subprocess.Popen(
                command, 
                shell=True, 
                stdout=subprocess.PIPE, 
                stderr=subprocess.PIPE,
                text=True
            )
            
            if wait_for_completion:
                stdout, stderr = process.communicate()
                return_code = process.returncode
                
                if return_code == 0:
                    return {
                        "success": True, 
                        "message": "命令执行成功",
                        "output": stdout,
                        "return_code": return_code
                    }
                else:
                    return {
                        "success": False, 
                        "message": f"命令执行失败，返回代码: {return_code}",
                        "output": stdout,
                        "error": stderr,
                        "return_code": return_code
                    }
            else:
                return {
                    "success": True, 
                    "message": "命令已启动，将在后台运行",
                    "process_id": process.pid
                }
        except Exception as e:
            return {"success": False, "message": f"执行命令失败: {str(e)}"}

# 工具函数别名，方便直接使用
create_text_file = FileTools.create_text_file
create_python_file = FileTools.create_python_file
get_directory_structure = FileTools.get_directory_structure
rename_file = FileTools.rename_file
execute_windows_command = CommandTools.execute_windows_command

# 示例使用
if __name__ == "__main__":
    # 创建一个文本文件
    print(create_text_file("test_folder/test.txt", "这是一个测试文件"))
    
    # 创建一个Python文件
    print(create_python_file("test_folder/script.py", "print('Hello, World!')"))
    
    # 获取目录结构
    print(get_directory_structure("test_folder"))
    
    # 重命名文件
    print(rename_file("test_folder/test.txt", "new_test.txt"))
    
    # 执行Windows命令
    print(execute_windows_command("dir"))    